package com.yxplearn.mybatisplus.mybatisplus_simple.type_handler;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

public class SetTypeHandler extends AbstractCollectionTypeHandler<Set<Object>> {

    @Override
    public Set<Object> parseToCollection(String value) {
        Set<Object> set = new HashSet<>();
        String[] split = value.split(";");
        for (int i = 0; i < split.length; i++) {
            set.add(split[i]);
        }
        return set;
    }

    @Override
    public String parseToString(Set<Object> set) {
        StringBuilder stringBuilder = new StringBuilder();
        set.forEach(e -> stringBuilder.append(e.toString()).append(";"));
        return stringBuilder.toString();
    }
}
